package com.sfy.course.controller;


import ch.qos.logback.classic.spi.EventArgUtil;
import com.sfy.common.dto.CourseDTO;
import com.sfy.course.dataObject.Course;
import com.sfy.course.msmapper.MsCourseMapper;
import com.sfy.course.service.CourseService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/courses")
public class CourseController {


    private final CourseService courseService;
    private final MsCourseMapper msCourseMapper;

    @GetMapping("/{courseId}")
    public ResponseEntity<CourseDTO> getCourse(@PathVariable("courseId") Long courseId) {
        Course course = courseService.getById(courseId);
        if (course == null) {
            return ResponseEntity.notFound().build();
        }
        CourseDTO courseDTO = msCourseMapper.toDtO(course);
        return ResponseEntity.ok(courseDTO);
    }
}
